<?php
session_start();
include("../model/database.php");
include("../model/xl_nguoi_dung.php");
$xl_nguoi_dung=new xl_nguoi_dung();

$manguoidung = $_REQUEST['usid'];
$nguoidung1 = $xl_nguoi_dung->layNguoiDung($manguoidung);
$hinhanh = $nguoidung1[0]['HinhAnhDaiDien'];

if($hinhanh!="")
	unlink('../uploads/user/'.$hinhanh);

$uploaddir = '../uploads/user/'; 
$file = $uploaddir ."diadiem_".$manguoidung.basename($_FILES['uploadfile']['name']); 
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
	if($xl_nguoi_dung->themAnhNguoiDung($manguoidung,"diadiem_".$manguoidung.basename($_FILES['uploadfile']['name']))){
		$nguoidung = $xl_nguoi_dung->layNguoiDung($manguoidung);
		$row = $nguoidung[0];
		$_SESSION['usid'] = $manguoidung;
		$_SESSION['email'] = $row['Email'];
		$_SESSION['ava'] = $row['HinhAnhDaiDien'];
		$_SESSION['fullname'] = $row['TenHienThi'];
		$_SESSION['oauth'] = $row['oauth_provider'];
  		echo "success"; 
	}
} else {
	echo "error";
}
?>
